{extend name="common/base" /}
{block name='title'}编辑课程目录 - 资讯管理{/block}

{block name="body"}
    <article class="Hui-admin-page-container">
        <form class="form form-horizontal" id="form-article-add">
            <input name="id" value="{$data.id}" type="hidden">
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>课程目录标题：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$data.title}" placeholder="" id="title" name="title">
                </div>
            </div>
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>简略标题：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$data.title_en}" placeholder="" id="title_en" name="title_en">
                </div>
            </div>
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2">讲师：</label>
                <div class="form-controls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
                    <select class="select" name="lecturer" size="1">
                        {foreach $lecturer as $k=>$v}
                        <option {if $data.lid == $v.id}selected{/if} value="{$v.id}">{$v.title}</option>
                        {/foreach}
                    </select>
                    </span> 
                </div>
            </div>
            
            
  
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>排序值：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$data.sort}" placeholder="" id="articleSort" name="sort">
                </div>
            </div>
         
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2">时长：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$data.duration}" placeholder="" id="duration" name="duration">
                </div>
            </div>

            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2">付费：</label>
                <div class="form-controls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input name="is_pay" type="radio" value="1" {if $data.is_pay == 1}checked{/if} id="sex-1" >
                        <label for="sex-1">是</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="sex-2" value="-1" {if $data.is_pay == -1}checked{/if} name="is_pay">
                        <label for="sex-2">否</label>
                    </div>
                </div>
            </div>
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2">新版：</label>
                <div class="form-controls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input name="is_new" type="radio" {if $data.is_new == 1}checked{/if} value="1" id="sex-1" >
                        <label for="sex-1">是</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="sex-2" value="-1" {if $data.is_new == -1}checked{/if} name="is_new">
                        <label for="sex-2">否</label>
                    </div>
                </div>
            </div>

            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2">视频：</label>
                <div class="form-controls col-xs-8 col-sm-9" >
                    <span class="btn-upload">
                        <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                        <input type="file"  name="btn-upload-vedio" id="uploadVideoNow-file" class="input-file">
                    </span>
                    <span id="uploadProgress" style="display:none">上传进度：<span id="uploadProgressNum">0</span>%</span>
                </div>
            </div>
            <div class="row clearfix">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                    <button class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
                    <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                </div>
            </div>
        </form>
    </article>
    <input name="uploadVedio" type="hidden" value="{:url('upload/uploadVedio')}">
    <input name="link" type="hidden" value="{$data.link}">
    <input name="FileId" type="hidden" value="{$data.FileId}">
    <input name="cid" type="hidden" value="{$cid}">
    <input name="signUrl" type="hidden" value="{$signUrl}">


{/block}

{block name="js"}
<!--请在下方写此页面业务相关的脚本-->
  <script src="//imgcache.qq.com/open/qcloud/js/vod/sdk/ugcUploader.js"></script>

<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__LIB__/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="__JS__/main.js"></script>
<script type="text/javascript">
    $(function(){
        // 复选框样式
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        // 是否评论
        $('#articleComment').on('ifChecked', function(event){
            $("#comment-datetime-start,#comment-datetime-end").attr("disabled",false).removeClass("disabled");
        });
        $('#articleComment').on('ifUnchecked', function(event){
            $("#comment-datetime-start,#comment-datetime-end").attr("disabled",true).addClass("disabled");
        });

        // 设置评论日期
        $("#comment-datetime-start").datetimepicker({
        format: 'yyyy-mm-dd',
        minView: "month",
        todayBtn:  1,
        autoclose: 1,
        endDate : new Date(),
      }).on('changeDate', function(event) {
        event.preventDefault();
        event.stopPropagation();
        var startTime = event.date;
        $('#search-datetime-end').datetimepicker('setStartDate',startTime);
      });
      $("#comment-datetime-end").datetimepicker({
        format: 'yyyy-mm-dd',
        minView: "month",
        todayBtn:  1,
        autoclose: 1,
        endDate : new Date(),
      }).on('changeDate', function(event) {
        event.preventDefault();
        event.stopPropagation();
        var endTime = event.date;
        $("#search-datetime-start").datetimepicker('setEndDate',endTime);
      });

        // 课程目录摘要
        $(".textarea-article").Huitextarealength({
            minlength: 10,
            maxlength: 500
        });

        // 课程目录内容 实例化百度富文本编辑器
        var ue = UE.getEditor('articleEditor');

        // 表单提交验证
        $("#form-article-add").validate({
            rules: {
                title: {
                    required: true,
                },
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function(form){
                var url = "{:url('course_menu/edit')}";
                var id = $("input[name='id']").val();
                var cid = $("input[name='cid']").val();
                var title = $("input[name='title']").val();
                var lid = $("select[name='lecturer']").val();
                var duration = $("select[name='duration']").val();
                var title_en = $("input[name='title_en']").val();
                var link = $("input[name='link']").val();
                var FileId = $("input[name='FileId']").val();
                var sort = $("input[name='sort']").val();
                var is_new = $("input[name='is_new']:checked").val();
                var is_pay = $("input[name='is_pay']:checked").val();
                var duration = $("#duration").val();
                
                
                $.ajax({
                    url : url ,
                    type : 'post',
                    dataType : 'json',
                    data : {
                        cid : cid,
                        title : title,
                        lid : lid,
                        title_en : title_en,
                        duration : duration,
                        link : link,
                        FileId : FileId,
                        is_new : is_new,
                        sort : sort,
                        is_pay : is_pay,
                        id : id,
                        duration : duration,
                    },
                    success :function(ret){
                        if(0 == ret.code){
                            layer.msg(ret.msg, { icon:1,time:1000 });
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.replace(parent.location.href)
                            parent.layer.close(index);
                        }else{
                            layer.msg(ret.msg, { icon:2,time:1000 });
                        }
                    }
                });
                //$(form).ajaxSubmit();
            }
        });
    });
    
</script>
<!--/请在上方写此页面业务相关的脚本-->
{/block}